package com.rover.crm.service;

import com.grid.DataGrid;
import com.grid.Page;
import com.rover.crm.entity.SalesOfProducts;


import com.rover.system.service.BaseService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 产品Service
*/

@Service
@Transactional
public class SalesOfProductsService extends BaseService {
protected Logger logger = LoggerFactory.getLogger(getClass());

@Transactional
public DataGrid query(Page page) throws Exception {
DataGrid dataGrid = new DataGrid();
page.setFieldList(" sp ");
page.setTableName(" SalesOfProducts sp left outer join sp.businessOpportunities bo ");
if(StringUtils.isNotBlank(page.getParameter("businessOpportunitiesId"))){
    page.setWhere("  bo.id=:businessOpportunitiesId");
    Map<String,Object> params=new HashMap<String,Object>();
    params.put("businessOpportunitiesId",Integer.valueOf( page.getParameter("businessOpportunitiesId")));
    page.setWhereParams(params);
}

List<SalesOfProducts> li = dao.<SalesOfProducts>findPageHql(page.getHQL(), page.getWhereParams(), page.getPageNo(),
    page.getPageSize());
    dataGrid.setResult(li);
    dataGrid.setTotalCount(dao.countHql(page.getHQLTotalCount(), page.getWhereParams()));
    return dataGrid;
    }



}
